package com.javasm.crm.service.impl.productimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.criteria.GoodsCriteria;
import com.javasm.crm.domin.criteria.TypeCriteria;
import com.javasm.crm.domin.entity.productEntity.GoodsVo;
import com.javasm.crm.domin.entity.productEntity.TypeBrandVo;
import com.javasm.crm.mapper.goodsmapper.GoodsVoMapper;
import com.javasm.crm.mapper.goodsmapper.TypeBrandVoMapper;
import com.javasm.crm.service.productservice.GoodsVoService;
import com.javasm.crm.service.productservice.TypeBrandVoService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @Author：zhangyang
 * @Version：1.0
 * @Date：2021/7/14-10:23
 * @desp:
 * @since:
 */
@Service
@Transactional
public class TypeBrandVoServiceImpl extends ServiceImpl<TypeBrandVoMapper, TypeBrandVo> implements TypeBrandVoService {
    @Autowired
    TypeBrandVoMapper typeBrandVoMapper;

    @Override
    public PageResult<TypeBrandVo> searchPageByCriteria(TypeCriteria typeCriteria) {
        Integer currentPage = typeCriteria.getCurrentPage();

        Integer pageSize = typeCriteria.getPageSize();
        if (StringUtils.isEmpty(currentPage)) {
            currentPage = 1;
        }
        if (StringUtils.isEmpty(pageSize)) {
            pageSize = 5;
        }
        QueryWrapper<TypeBrandVo> exampleQueryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(typeCriteria.getTypeName())){
            exampleQueryWrapper.like("t.type_name",typeCriteria.getTypeName());
        }
        Page<TypeBrandVo> examplePage = new Page<>(currentPage, pageSize);
        List<TypeBrandVo> queryall = typeBrandVoMapper.queryall(examplePage, exampleQueryWrapper);

        return new PageResult<TypeBrandVo>(examplePage.getTotal(), queryall);
    }
}
